package com.ocom.human.controller;


import com.ocom.common.constant.HumanServiceUrl;
import com.ocom.common.entity.master.EntityWechatPerInfo;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.human.service.WechatPerInfoService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class WechatPerInfoController {

    @Autowired
    WechatPerInfoService wechatPerInfoService;


    @PostMapping(HumanServiceUrl.URLP_HUAMN_ADD_WXPER)
    public Result addWxper(@RequestBody EntityWechatPerInfo wechatPerInfo){
        EntityWechatPerInfo entityWechatPerInfo=wechatPerInfoService.saveWxUser(wechatPerInfo);
        if(entityWechatPerInfo==null){
            return ResultUtil.error(ResultEnum.Err_3011);
        }else{
            return ResultUtil.success(entityWechatPerInfo);
        }
    }

    @PostMapping(HumanServiceUrl.URLP_getWxUserByPid)
    public Result getWxUserByPid(Long companyId,Long pId,@RequestParam(value = "appId",defaultValue = "")String appId){
        EntityWechatPerInfo entityWechatPerInfo=wechatPerInfoService.getWxUserByPid(companyId,pId,appId);
        return ResultUtil.success(entityWechatPerInfo);
    }


    /**
     * 获取微信人员(getWxPerson)
     * */
    @GetMapping(HumanServiceUrl.URL_GetWxPerson)
    public Result GetWxPerson(String appId,String openId ,@RequestParam(value = "comId",defaultValue = "0")Long comId){
        log.info("获取微信人员请求参数{{}},{{}}",appId,openId);
        return ResultUtil.success(wechatPerInfoService.GetWxPerson(appId,openId,comId));
    }

    /**
     * 删除微信绑定人员(delWxPerson)
     * */
    @PostMapping(HumanServiceUrl.URL_DelWxPerson)
    public Result DelWxPerson(String appId,String openId){
        log.info("删除微信绑定人员请求参数{{}},{{}}",appId,openId);
        try {
            wechatPerInfoService.DelWxPerson(appId,openId);
        }catch (Exception exception){
            log.info("删除微信绑定人员失败{{}}",exception.getMessage());
        }
        return ResultUtil.success();
    }

    /**
     * 获取微信管理员角色列表
     * */
    @PostMapping(HumanServiceUrl.URL_getWxAdminInfo)
    public Result getWxAdminInfo(String appId,String openId){
        return ResultUtil.success(wechatPerInfoService.getWxAdminInfo(appId,openId));
    }

}
